package com.base.andlanggl

import androidx.lifecycle.ViewModelProvider
import com.alibaba.android.arouter.facade.annotation.Route
import com.base.andlangcore.mvvm.AndLangActivity
import com.base.andlangcore.mvvm.AndLangModel
import com.base.andlanggl.databinding.ActivityOpenglBinding
import com.base.andlanggl.render.LangGLRender
import com.base.andlanggl.util.LangGLTools
import com.base.andlangrouter.RouteUrl
import com.base.andlangui.weight.ToastKt.toast

@Route(path = RouteUrl.GL_MAIN_OPENGL)
class OpenglActivity : AndLangActivity<ActivityOpenglBinding,AndLangModel>() {
    private val render:LangGLRender by lazy { LangGLRender(this) }
    override fun getViewBinding(): ActivityOpenglBinding {
        return ActivityOpenglBinding.inflate(layoutInflater)
    }

    override fun getVM(): AndLangModel {
        return ViewModelProvider(this)[AndLangModel::class.java]
    }

    override fun initView() {
        vb?.apply{
            if(LangGLTools.ifSupportES2(this@OpenglActivity)){
                glView.setEGLContextClientVersion(2)
                glView.setRenderer(render)
                //注册生命周期的监听对象
                lifecycle.addObserver(glView)
            }else{
                toast("不支持OpenGL ES 2.0")
            }
        }
    }

    override fun initData() {

    }
}